package com.foreveross.bsl.common.utils.balance.cxf;

import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.feature.AbstractFeature;

/**
 * This feature may be applied to a Client so as to enable
 * load balance , use any compatible endpoint for the target service.
 *
 * @author Vector Ho  Date:2014-10-17 23:26
 * @see org.apache.cxf.clustering.FailoverFeature
 */
public class LoadBalanceFeature extends AbstractFeature {
	
    private LoadBalanceStrategy loadBalanceStrategy; // 策略入口

    @Override
    public void initialize(Client client, Bus bus) {
        LoadBalanceTargetSelector selector = new LoadBalanceTargetSelector();
        selector.setEndpoint(client.getEndpoint());
        selector.setStrategy(this.getStrategy());
        client.setConduitSelector(selector);
    }

    public void setStrategy(LoadBalanceStrategy strategy) {
        loadBalanceStrategy = strategy;
    }

    public LoadBalanceStrategy getStrategy() {
        return loadBalanceStrategy;
    }

}
